//============================================================================
// Name        : Packet.h
// Author      : Jonathan Ellithorpe and Allen Lee
// Version     :
// Copyright   : UC Berkeley
// Description : The packet class abstracts away the idea of a GNUT packet. This class
//	keeps the header in network byte order, and provides functionality on
//	that header and packet payload to make accessing packet data and header
//	information easy as A, B, C.
//============================================================================

#ifndef PACKET_H_
#define PACKET_H_

#include "stdGNUTDefs.h"

class Packet
{
private:
	GNUT_Packet_t myPacket;
	char* myPacketByteArray;

public:
	Packet();
	Packet(short srcPort, short dstPort, int SeqAck, int AdvWindow, int type, char* payload, int length);
	Packet(char* buffPtr, unsigned int length);
	void setPacket(short srcPort, short dstPort, int SeqAck, int AdvWindow, int type, char* payload, int length);
	void setPacket(char* buffPtr, unsigned int length);
	virtual ~Packet();
	unsigned short getSrcPort();
	unsigned short getDstPort();
	unsigned int getSeqNo();
	unsigned int getAckNo();
	unsigned int getAdvWindow();
	unsigned short getType();
	unsigned short getSize();
	unsigned short getCheckSum();
	char* getPayload();
	unsigned int getPayloadLength();
	void setSrcPort(unsigned short);
	void setDstPort(unsigned short);
	void setSeqNo(unsigned int);
	void setAckNo(unsigned int);
	void setAdvWindow(unsigned int);
	void setType(unsigned int);
	void setPayload(char* payload, int length);
	void updateSize();
	void updateCheckSum();
	bool isACK();
	bool isSYN();
	bool isFIN();
	bool isRST();
	bool isDAT();
	bool checkCheckSum();
	char* toBytes();
	void freeBytes();
	unsigned short computeCheckSum();
	int printPacket();
};



#endif /*PACKET_H_*/
